/**
 * 
 */
package ee.fujitsu.entity;

import java.util.Date;

import ee.fujitsu.payments.BonusCounting;
import ee.fujitsu.payments.PaymentStyle;

/**
 * The Class JournalRecord.
 *
 * @author Andrei
 * 
 * 06.09.2012
 * class of records into store journal
 */
public  class JournalRecord {
	
	/** The Constant MILLIS_IN_DAY. */
	private static final int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;  
	
	/** The Constant BONUS_ACTION. */
	public static final int BONUS_ACTION = 25;  

	/** The payment. */
	protected PaymentStyle payment;
	
	/** The bonus. */
	protected BonusCounting bonus;

	/** The start. */
	private Date start;
	
	/** The expected end. */
	private Date expectedEnd;
	
	/** The real end. */
	private Date realEnd;
	
	/** The movie. */
	private Movie movie;
	
	/** The customer. */
	private Customer customer;
	
	/** The fpayment. */
	private double fpayment;
	
	/** The spayment. */
	private double spayment;
	
	/** The active bonus. */
	private boolean activeBonus = false; 
	
	/** The bonus days. */
	private int bonusDays;
	
	/**
	 * Checks if is active bonus.
	 *
	 * @return the activeBonus
	 */
	public boolean isActiveBonus() {
		return activeBonus;
	}

	/**
	 * Sets the active bonus.
	 *
	 * @param activeBonus the activeBonus to set
	 */
	public void setActiveBonus(boolean activeBonus) {
		this.activeBonus = activeBonus;
	}

	/**
	 * Instantiates a new journal record.
	 *
	 * @param movie the movie
	 * @param start the start
	 * @param expectedEnd the expected end
	 * @param realEnd the real end
	 * @param customer the customer
	 */
	public JournalRecord (Movie movie, Date start, Date expectedEnd, Date realEnd, Customer customer ) {
		this.movie = movie;
		this.start = start;
		this.expectedEnd = expectedEnd;
		this.realEnd = realEnd;
		this.customer = customer;
	}

	/**
	 * Day difference.
	 *
	 * @return the int
	 */
	public int dayDifference() {
		Long diff = (expectedEnd.getTime() - start.getTime()) / MILLIS_IN_DAY;
		return diff.intValue();
	}
	
	/**
	 * Day overhead.
	 *
	 * @return the int
	 */
	public int dayOverhead() {
		if (realEnd != null) {
			Long diff = (realEnd.getTime() - expectedEnd.getTime()) / MILLIS_IN_DAY;
			return diff.intValue();
		} else	
			return 0;
	}

	/**
	 * Gets the bonus days.
	 *
	 * @return the bonusDays
	 */
	public int getBonusDays() {
		return bonusDays;
	}

	/**
	 * Sets the bonus days.
	 *
	 * @param bonusDays the bonusDays to set
	 */
	public void setBonusDays(int bonusDays) {
		this.bonusDays = bonusDays;
	}

	/**
	 * Perform payment.
	 */
	public void performPayment() {
		int bonusDay = 0;
		if (customer.getBonus() > BONUS_ACTION) {
			activeBonus = true;
			bonusDays = customer.getBonus() / BONUS_ACTION ;
			customer.setBonus(customer.getBonus() % BONUS_ACTION);
		}
		fpayment = payment.getRegulapPayment(dayDifference() - bonusDay);
			
	}
	
	/**
	 * Inits the payment.
	 */
	public void initPayment() {
		fpayment = payment.getRegulapPayment(dayDifference());
	}
	
	/**
	 * Second payment.
	 */
	public void secondPayment() {
		spayment = payment.getPaymentDelay(dayOverhead());
	}

	/**
	 * Perform bonus.
	 */
	public void performBonus() {
		customer.setBonus(customer.getBonus() + bonus.getBonus());
	}
		
	/**
	 * Gets the fpayment.
	 *
	 * @return the fpayment
	 */
	public double getFpayment() {
		return fpayment;
	}

	/**
	 * Sets the fpayment.
	 *
	 * @param fpayment the fpayment to set
	 */
	public void setFpayment(double fpayment) {
		this.fpayment = fpayment;
	}

	/**
	 * Gets the spayment.
	 *
	 * @return the spayment
	 */
	public double getSpayment() {
		return spayment;
	}

	/**
	 * Sets the spayment.
	 *
	 * @param spayment the spayment to set
	 */
	public void setSpayment(double spayment) {
		this.spayment = spayment;
	}

	/**
	 * Gets the customer.
	 *
	 * @return the customer
	 */
	public Customer getCustomer() {
		return customer;
	}

	/**
	 * Sets the customer.
	 *
	 * @param customer the customer to set
	 */
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * Gets the start.
	 *
	 * @return the start
	 */
	public Date getStart() {
		return start;
	}

	/**
	 * Sets the start.
	 *
	 * @param start the start to set
	 */
	public void setStart(Date start) {
		this.start = start;
	}

	/**
	 * Gets the expected end.
	 *
	 * @return the expectedEnd
	 */
	public Date getExpectedEnd() {
		return expectedEnd;
	}

	/**
	 * Sets the expected end.
	 *
	 * @param expectedEnd the expectedEnd to set
	 */
	public void setExpectedEnd(Date expectedEnd) {
		this.expectedEnd = expectedEnd;
	}

	/**
	 * Gets the real end.
	 *
	 * @return the realEnd
	 */
	public Date getRealEnd() {
		return realEnd;
	}

	/**
	 * Sets the real end.
	 *
	 * @param realEnd the realEnd to set
	 */
	public void setRealEnd(Date realEnd) {
		this.realEnd = realEnd;
	}

	/**
	 * Gets the movie.
	 *
	 * @return the movie
	 */
	public Movie getMovie() {
		return movie;
	}

	/**
	 * Sets the movie.
	 *
	 * @param movie the movie to set
	 */
	public void setMovie(Movie movie) {
		this.movie = movie;
	}

//	public JournalRecord () {
//	}
//
//	public JournalRecord (Movie movie, Date start, Date expectedEnd, Customer customer) {
//		this.movie = movie;
//		this.start = start;
//		this.expectedEnd = expectedEnd;
//		this.customer = customer;
//	}
	
	

}
